package com.john.bluetoothtest2;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button btn_log_in;
private Button btn_register;



    private long firstTime=0;

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch(keyCode){
            case KeyEvent.KEYCODE_BACK://点击返回键
                long secondTime = System.currentTimeMillis();//以毫秒为单位
                if(secondTime -firstTime>2000){
                    Toast.makeText(this, "再按一次返回退出程序", Toast.LENGTH_SHORT).show();
                    firstTime=secondTime;
                }else{
                    finish();
                    System.exit(0);
                }
                return true;
        }
        return super.onKeyUp(keyCode, event);
    }


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Window window = getWindow();
        window.setStatusBarColor(ContextCompat.getColor(this,R.color.white1));

        btn_log_in=findViewById(R.id.btn_log_in);
         btn_register=findViewById(R.id.btn_register);
         btn_log_in.setOnClickListener(this);
         btn_register.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
switch (view.getId()){
    case R.id.btn_log_in:
        log_in();
        break;
    case R.id.btn_register:
        register();
        break;
    default:
        break;
}
    }

    private void register() {
        Intent intent1=new Intent(MainActivity.this, RegisterActivity.class);
        startActivity(intent1);

    }

    private void log_in() {
        Intent intent2=new Intent(MainActivity.this, LoginActivity.class);
        startActivity(intent2);
        finish();
    }




}